package com.apes.fn.tms.service;

import com.apes.fn.tms.model.BranchLine;
import com.apes.fn.tms.model.BranchShift;
import com.apes.fn.tms.repository.BranchLineRepository;
import com.apes.fn.tms.repository.BranchShiftRepository;
import com.apes.framework.api.DomainService;
import com.apes.framework.plugin.esb.api.SimpleRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("branchShiftService")
public class BranchShiftService extends DomainService {
    @Autowired
    BranchShiftRepository branchShiftRepository;

    public BranchShift create(SimpleRequest simpleRequest){
        BranchShift branchShift = simpleRequest.getO(BranchShift.class);
        return branchShiftRepository.saveAndFlush(branchShift);
    }

    public BranchShift update(SimpleRequest simpleRequest){
        BranchShift branchShift = simpleRequest.getO(BranchShift.class);
        return branchShiftRepository.saveAndFlush(branchShift);
    }

    private String delete(SimpleRequest simpleRequest){
        Integer versions = simpleRequest.get("version");
        BranchShift branchShift = simpleRequest.getO(BranchShift.class);
        if (branchShift.getVersion() != versions) throw new RuntimeException("记录已更新或已删除，请重新提交！");
        branchShiftRepository.delete(branchShift);
        return "删除成功";
    }

}
